package com.gary.gc;

/**
 * @author peng_rui
 * @date 2022/3/6
 */
public class JProfileGCRoot {

    public static JProfileGCRoot obj = null;

    public Integer num;

    @Override
    protected void finalize() throws Throwable {
        System.out.println("I will dead");
        obj = this;
        System.out.println("I refile ...");
    }

    public static void main(String[] args) {
        try {
            obj = new JProfileGCRoot();
            obj.num = 1;
//            obj = null;
//            System.gc();
//            Thread.sleep(10000);
//            if (obj == null) {
//                System.out.println("dead");
//            } else {
//                System.out.println("obj live...");
//            }
//            obj = null;
//            System.gc();
            Thread.sleep(10000000);
//            if (obj == null) {
//                System.out.println("dead");
//            } else {
//                System.out.println("obj live...");
//            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
